package com.huawei.hianalytics.util;

import android.content.Context;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class b {
    public static List<String> a(Context context) {
        Closeable open;
        Throwable th;
        Throwable th2;
        if (context != null) {
            Closeable closeable = null;
            try {
                open = context.getResources().getAssets().open("hianalytics_config");
            } catch (IOException e) {
                try {
                    com.huawei.hianalytics.g.b.c("HiAnalytics/event", "read preBaseUri error,the file is corrupted");
                    f.a(7, closeable);
                    return new ArrayList();
                } catch (Throwable th3) {
                    th = th3;
                    open = closeable;
                    th2 = th;
                    f.a(7, open);
                    throw th2;
                }
            } catch (JSONException e2) {
                open = null;
                try {
                    com.huawei.hianalytics.g.b.c("HiAnalytics/event", "preBaseUri config is no json");
                    f.a(7, open);
                    return new ArrayList();
                } catch (Throwable th4) {
                    th2 = th4;
                    f.a(7, open);
                    throw th2;
                }
            } catch (Exception e3) {
                open = null;
                com.huawei.hianalytics.g.b.c("HiAnalytics/event", "preBaseUri config other exception");
                f.a(7, open);
                return new ArrayList();
            } catch (Throwable th32) {
                th = th32;
                open = null;
                th2 = th;
                f.a(7, open);
                throw th2;
            }
            try {
                JSONArray jSONArray = new JSONObject(f.a((InputStream) open, 2048)).getJSONArray("base_uri");
                List arrayList;
                if (jSONArray == null) {
                    com.huawei.hianalytics.g.b.c("HiAnalytics/event", "not found base_uri");
                    arrayList = new ArrayList();
                    f.a(7, open);
                    return arrayList;
                }
                int length = jSONArray.length();
                if (length == 0 || length > 13) {
                    com.huawei.hianalytics.g.b.c("HiAnalytics/event", "preBaseUri config is error,Number error of URI");
                    arrayList = new ArrayList();
                    f.a(7, open);
                    return arrayList;
                }
                List<String> arrayList2 = new ArrayList();
                for (int i = 0; i < length; i++) {
                    String optString = jSONArray.optString(i, "");
                    if (h.a(optString)) {
                        arrayList2.add(optString);
                    }
                }
                f.a(7, open);
                return arrayList2;
            } catch (IOException e4) {
                closeable = open;
                com.huawei.hianalytics.g.b.c("HiAnalytics/event", "read preBaseUri error,the file is corrupted");
                f.a(7, closeable);
                return new ArrayList();
            } catch (JSONException e5) {
                com.huawei.hianalytics.g.b.c("HiAnalytics/event", "preBaseUri config is no json");
                f.a(7, open);
                return new ArrayList();
            } catch (Exception e6) {
                com.huawei.hianalytics.g.b.c("HiAnalytics/event", "preBaseUri config other exception");
                f.a(7, open);
                return new ArrayList();
            }
        }
        return new ArrayList();
    }
}
